const { SM2 } = require('gm-crypto')

let { publicKey, privateKey } = SM2.generateKeyPair()
console.log(publicKey)
const originalData = 'SM2 椭圆曲线公钥密码算法'
//                                                     04e8d57ab47fa6292690da97774a7012e639b85b505dddbb5e0744c18528ac36f4b31ded4c7501263cc941eb0326d39b53d65b5b182afa51c795a87162b65cb403
// 3059301306072a8648ce3d020106082a811ccf5501822d03420004cd03ca128b4f56c7c7ad5aa550922d80319cffcafe4f97b5c449e79438eb39d241f6e1cf37cb48f1666145bb781016833c1dd98b98997908695c87a3a7481751
publicKey = '04cd03ca128b4f56c7c7ad5aa550922d80319cffcafe4f97b5c449e79438eb39d241f6e1cf37cb48f1666145bb781016833c1dd98b98997908695c87a3a7481751'


// 纯签名 + 生成椭圆曲线点
let sigValueHex = SM2.doSignature(originalData, privateKey);
let verifyResult = sm2.doVerifySignature(msgString, sigValueHex, publicKey);
const encryptedData = SM2.encrypt(originalData, publicKey, {
    inputEncoding: 'utf8',
    outputEncoding: 'hex'
})

const decryptedData = SM2.decrypt(encryptedData, privateKey, {
    inputEncoding: 'hex',
    outputEncoding: 'utf8'
})

console.log(encryptedData)
console.log(2, decryptedData)